﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.IO;

namespace blacksoft.Controllers
{
    
    class Usupador
    {
        public string HTML;
        private string CONTENIDOAUX;

        public Usupador(string URL)
        {
            WebRequest request = WebRequest.Create(URL);
            request.Proxy = null;

            using (var response = (HttpWebResponse)request.GetResponse())
            {

                using (Stream s = response.GetResponseStream())
                {
                    Encoding eCodificacion = Encoding.GetEncoding(response.CharacterSet);
                    StreamReader sr = new StreamReader(s, eCodificacion);
                    this.HTML = sr.ReadToEnd();
                    this.CONTENIDOAUX = this.HTML;
                    sr.Close();
                }
            }
        }
        public string SacarContenido(string INI, string FIN) {
            int pFrom = this.HTML.IndexOf(INI) + INI.Length;
            string part1 = this.HTML.Substring(pFrom);
            int pTo = part1.IndexOf(FIN);
            return part1.Substring(0, pTo);
        }
        public string SacarContenidoCortando(string INI, string FIN)
        {
            int pFrom = this.CONTENIDOAUX.IndexOf(INI) + INI.Length;
            this.CONTENIDOAUX = this.CONTENIDOAUX.Substring(pFrom);
            int pTo = this.CONTENIDOAUX.IndexOf(FIN);
            string retornar = this.CONTENIDOAUX.Substring(0, pTo);
            pFrom = FIN.Length;
            this.CONTENIDOAUX = this.CONTENIDOAUX.Substring(pTo + pFrom);
            return retornar;
        }
        public void avanzarHasta(string stri)
        {
            int pFrom = this.CONTENIDOAUX.IndexOf(stri) + stri.Length;
            this.CONTENIDOAUX = this.CONTENIDOAUX.Substring(pFrom);
        }
        public void restore()
        {
            this.CONTENIDOAUX = this.HTML;
        }
        
   

    }
}
